home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libpod / status.c.z / status.c
C/C++ Source or Header  |  1996-05-06  |  6KB  |  232 lines

  1. /**************************************************************************
  2.  *
  3.  *           Copyright (c)    1992 Silicon Graphics, Inc.
  4.  *            All Rights Reserved
  5.  *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  7.  *
  8.  * The copyright notice above does not evidence any actual of intended
  9.  * publication of such source code, and is an unpublished work by Silicon
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly
  13.  * prohibited.
  14.  *
  15.  * RESTRICTED RIGHTS LEGEND:
  16.  *
  17.  * Use, duplication or disclosure by the Government is subject to
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311
  24.  **************************************************************************
  25.  *
  26.  * File: status.c
  27.  *
  28.  * Description: Sample program that demonstrates the use of the standard
  29.  *    form of the libpod status read functions.
  30.  *
  31.  *    Usage: status printer_name
  32.  *
  33.  **************************************************************************/
  34.  
  35.  
  36. #ident "$Revision: 1.4 $"
  37.  
  38.  
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include <stdlib.h>
  42. #include <time.h>
  43. #include <pod.h>
  44.  
  45.  
  46. #define HANDLE_ERROR(pname)    { \
  47.                 PDPerror(pname); \
  48.                 exit(1); \
  49.                 }
  50.  
  51.  
  52. void usage(char*);
  53. void disp_opstatus(int);
  54. void disp_status(PDStatusStruct*, PDMessageStruct*);
  55. void disp_colorspace(int);
  56. void disp_depth(int);
  57. void disp_format(int);
  58.  
  59.  
  60. int main(int argc, char **argv)
  61. {
  62.     int opstatus;
  63.     PDStatusStruct *status;
  64.     PDMessageStruct *messages;
  65.     time_t mod_time;
  66.  
  67.     /*
  68.      * Get the printer name from command line
  69.      */
  70.     if (argc < 2) {
  71.     usage(argv[0]);
  72.     exit(1);
  73.     }
  74.  
  75.     /*
  76.      * Read and display only operational status
  77.      */
  78.     if (PDReadOpStatus(argv[1], &opstatus, &mod_time) < 0)
  79.     HANDLE_ERROR(argv[0]);
  80.     (void)printf("Current status summary - last modified %s\n",
  81.                             ctime(&mod_time));
  82.     disp_opstatus(opstatus);
  83.     (void)printf("\n");
  84.  
  85.     /*
  86.      * Read and display the full status and message information
  87.      */
  88.     if (PDReadStatus(argv[1], &status, &messages, &mod_time) < 0)
  89.     HANDLE_ERROR(argv[0]);
  90.     (void)printf("Current complete status - last modified %s\n",
  91.                             ctime(&mod_time));
  92.     disp_status(status, messages);
  93.  
  94.     return 0;
  95. }
  96.  
  97.  
  98. void usage(char *progname)
  99. {
  100.     (void)fprintf(stderr, "Usage: %s printer_name\n", progname);
  101. }
  102.  
  103.  
  104. void disp_opstatus(int status)
  105. {
  106.     (void)printf("\tOperational status:         ");
  107.     switch(status) {
  108.     case PD_STATUS_IDLE:
  109.         (void)printf("IDLE");
  110.         break;
  111.     case PD_STATUS_BUSY:
  112.         (void)printf("BUSY");
  113.         break;
  114.     case PD_STATUS_FAULTED:
  115.         (void)printf("FAULTED");
  116.         break;
  117.     case PD_STATUS_UNAVAILABLE:
  118.         (void)printf("UNAVAILABLE");
  119.         break;
  120.     default:
  121.         (void)printf("UNKNOWN");
  122.         break;
  123.     }
  124.     (void)printf("\n");
  125. }
  126.  
  127.  
  128. void disp_status(PDStatusStruct *status, PDMessageStruct *messages)
  129. {
  130.     register int i;
  131.     char *options;
  132.  
  133.     disp_opstatus(status->operational_status);
  134.     (void)printf("\tMedia type code:            %d\n", status->media_type);
  135.     (void)printf("\tNumber of colors code:      0x%08X\n",
  136.                         status->number_of_colors);
  137.     (void)printf("\t\tNumber of colors:   %d\n",
  138.                 PD_GET_NUMCOLORS(status->number_of_colors));
  139.     disp_colorspace(PD_GET_COLORSPACE_CODE(status->number_of_colors));
  140.     disp_depth(PD_GET_DEPTH_CODE(status->number_of_colors));
  141.     disp_format(PD_GET_FORMAT_CODE(status->number_of_colors));
  142.     (void)printf("\tMedia size code:            0x%08X\n", status->media_size);
  143.     (void)printf("\tMedia size name:            %s\n",
  144.             PDGetNameBySizeCode(status->media_size));
  145.     options = status->printer_options;
  146.     (void)printf("\tInstalled options:          %s\n",
  147.             (options && *options != '\0') ? options: "None");
  148.     (void)printf("\tMedia size validation mask: %d\n", status->validation_mask);
  149.     (void)printf("\tNumber of messages:         %d\n", status->error_count);
  150.     for (i = 0; i < status->error_count; i++) {
  151.     (void)printf("\n\t\tMessage %d code: 0x%08X\n", i+1,
  152.                     messages[i].message_code);
  153.     (void)printf("\t\tMessage %d text: %s\n", i+1,
  154.                     messages[i].message_text);
  155.     }
  156. }
  157.  
  158.  
  159. void disp_colorspace(int cspace)
  160. {
  161.     (void)printf("\t\tColorspace:         ");
  162.     switch(cspace) {
  163.         case PD_DATA_K:
  164.             (void)printf("k\n");
  165.         break;
  166.         case PD_DATA_CMY:
  167.             (void)printf("cmy\n");
  168.         break;
  169.         case PD_DATA_CMYK:
  170.             (void)printf("cmyk\n");
  171.         break;
  172.         case PD_DATA_W:
  173.             (void)printf("w\n");
  174.         break;
  175.         case PD_DATA_RGB:
  176.             (void)printf("rgb\n");
  177.         break;
  178.         case PD_DATA_YMC:
  179.             (void)printf("ymc\n");
  180.         break;
  181.         case PD_DATA_YMCK:
  182.             (void)printf("ymck\n");
  183.         break;
  184.         case PD_DATA_KCMY:
  185.             (void)printf("kcmy\n");
  186.         break;
  187.     default:
  188.             (void)printf("0x%08X\n", cspace);
  189.         break;
  190.     }
  191. }
  192.  
  193.  
  194. void disp_depth(int depth)
  195. {
  196.     (void)printf("\t\tDepth:              ");
  197.     switch(depth) {
  198.         case PD_DATA_DEPTH1:
  199.             (void)printf("1 bpp\n");
  200.         break;
  201.         case PD_DATA_DEPTH4:
  202.             (void)printf("4 bpp\n");
  203.         break;
  204.         case PD_DATA_DEPTH8:
  205.             (void)printf("8 bpp\n");
  206.         break;
  207.     default:
  208.             (void)printf("0x%08X\n", depth);
  209.         break;
  210.     }
  211. }
  212.  
  213.  
  214. void disp_format(int format)
  215. {
  216.     (void)printf("\t\tFormat:             ");
  217.     switch(format) {
  218.         case PD_DATA_CHUNKY:
  219.             (void)printf("chunky\n");
  220.         break;
  221.         case PD_DATA_BANDED:
  222.             (void)printf("banded\n");
  223.         break;
  224.         case PD_DATA_PLANAR:
  225.             (void)printf("planar\n");
  226.         break;
  227.     default:
  228.             (void)printf("0x%08X\n", format);
  229.         break;
  230.     }
  231. }
  232.